﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using saigonbook.Dal;

namespace saigonbook.Biz
{
    public class BIZ_user
    {
        public string username;
        public string password;
        public BIZ_phanquyen phanquyen;
        public string hoten;
        public DateTime ngaysinh;
        public int gioitinh;
        public string sodienthoai;
        public string diachi;
        public string email;
        public string Username
        {
            get { return username; }
            set { username = value; }
        }
        public string Password
        {
            get { return password; }
            set { password = value; }
        }
        public BIZ_phanquyen Phanquyen
        {
            get { return phanquyen; }
            set { phanquyen = value; }
        }

        public string Quyen
        {
            get { return Phanquyen == null ? String.Empty : Phanquyen.Quyen; }
        }

        public string Hoten
        {
            get { return hoten; }
            set { hoten = value; }
        }
        public DateTime Ngaysinh
        {
            get { return ngaysinh; }
            set { ngaysinh = value; }
        }
        public int Gioitinh
        {
            get { return gioitinh; }
            set { gioitinh = value; }
        }
        public string Sodienthoai
        {
            get { return sodienthoai; }
            set { sodienthoai = value; }
        }
        public string Diachi
        {
            get { return diachi; }
            set { diachi = value; }
        }
        public string Email
        {
            get { return email; }
            set { email = value; }
        }
        public BIZ_user()
        { }
        public BIZ_user(string username, string password, BIZ_phanquyen phanquyen, string hoten, DateTime ngaysinh, int gioitinh, string sodienthoai, string diachi, string email)
        {
            this.username = username;
            this.password = password;
            this.phanquyen = phanquyen;
            this.hoten = hoten;
            this.ngaysinh = ngaysinh;
            this.gioitinh = gioitinh;
            this.sodienthoai = sodienthoai;
            this.diachi = diachi;
            this.email = email;
        }
        public List<BIZ_user> Select_user()
        {
            return DAL_user.Select_user();
        }
        public void Them_user(BIZ_user dto)
        {
            DAL_user.Them_user(dto);
        }
        public void Sua_user(BIZ_user dto)
        {
            DAL_user.Sua_user(dto);
        }

        public BIZ_user Thongtin_user(string username)
        {
            List<BIZ_user> ds = new List<BIZ_user>();
            ds = DAL_user.Select_user();
            ds = (from u in ds where u.username.Equals(username) select u).Take(1).ToList();
            foreach (BIZ_user us in ds)
                return us;
            return null;
        }

        public bool dangnhapthanhcong(BIZ_user nhanvien)
        {
            List<BIZ_user> ds = Select_user();
            List<BIZ_user> dsdn = new List<BIZ_user>();
            dsdn = ds.Where(nv => (nhanvien.username == nv.username && nhanvien.password == nv.password && nv.phanquyen.maphanquyen == 2)).ToList();
            if (dsdn.Count > 0)
                return true;
            return false;
        }
    }
}
